const db = require("../models");
const Tech = db.tech;
const Depend = db.depend;

exports.findAll = (req, res)=>{
    Tech.findAll({
        order: db.sequelize.col('tech_level')
    })
    .then((data) => {
      res.setHeader("Access-Control-Allow-Origin",'*')
      res.send(data);
    })
    .catch((err) => {
      res.status(500).send({
        message: err.message || "查询所有技术出错",
      });
    });
}

exports.findOne = (req, res)=>{
    Tech.findOne({ where: { tech_id: req.query.tech_id } })
    .then((data) => {
      res.setHeader("Access-Control-Allow-Origin",'*')
      res.send(data);
    })
    .catch((err) => {
      res.status(500).send({
        message: err.message || "未查询到该技术",
      });
    });
}

exports.getDepend = (req, res)=>{
  //console.log(req)
  Depend.findAll({ where: { tech_id: req.query.tech_id } })
    .then((data) => {
        res.setHeader("Access-Control-Allow-Origin",'*')
        res.send(data);
    })
    .catch((err) => {
      res.status(500).send({
        message: err.message || "查询该技术所依赖技术失败",
      });
    });
}

exports.getNext = (req, res)=>{
  Depend.findAll({ where: { dep_id: req.query.tech_id } })
  .then((data) => {
      res.setHeader("Access-Control-Allow-Origin",'*')
      res.send(data);
  })
  .catch((err) => {
    res.status(500).send({
      message: err.message || "查询该技术所依赖技术失败",
    });
  });
}
